package org.jsola.hr.helper;

import org.jsola.hr.dto.ChannelAddDTO;
import org.jsola.hr.dto.ChannelUpdateDTO;
import org.jsola.hr.entity.ChannelDO;
import org.jsola.hr.query.ChannelQuery;
import org.jsola.hr.service.IChannelService;
import org.jsola.hr.vo.ChannelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 渠道管理
 *
 * @author zhr
 */
@Component
public class ChannelTestHelper extends BaseTestHelper {
    
    @Autowired
    private IChannelService channelService;

    /**
     * 生成add测试数据
     * @return ChannelAddDTO
     */
    public ChannelAddDTO getChannelAddDTO(){
        ChannelAddDTO channelAddDTO = new ChannelAddDTO();
        channelAddDTO.setChannelGroupId(getRandomValue("varchar",50));
        channelAddDTO.setAddress(getRandomValue("varchar",50));
        channelAddDTO.setName(getRandomValue("varchar",32));
        channelAddDTO.setPhone(getRandomValue("varchar",20));
        channelAddDTO.setIdcard(getRandomValue("varchar",18));
        channelAddDTO.setBankNo(getRandomValue("varchar",20));
        channelAddDTO.setAdminUserId(getRandomValue("varchar",32));
        return channelAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ChannelUpdateDTO
     */
    public ChannelUpdateDTO getChannelUpdateDTO(ChannelVO channelVO){
        return channelService.selectDOById(channelVO.getId(), SITE_ID).to(ChannelUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ChannelQuery
     */
    public ChannelQuery getChannelQuery() {
        ChannelQuery channelQuery = new ChannelQuery();
        List<ChannelDO> channelDOList = channelService.list(new ChannelDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(channelDOList)) {
            ChannelDO channelDO = channelDOList.get(0);
            channelQuery = channelDO.to(ChannelQuery.class);
        }
        return channelQuery;
    }

    /**
     * 保存示例
     * @return ChannelVO
     */
    public ChannelVO saveChannelExample(){
        ChannelAddDTO addDTO = this.getChannelAddDTO();
        ChannelVO channelVO = channelService.save(addDTO,true,buildTokenUser());
        return channelVO;
    }


}

